package service.Impl;


import dao.EmployeeDao;
import entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import service.EmployeeService;

import java.util.List;
import java.util.Objects;

/**
 * 员工服务实现类
 */
@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeDao employeeDao;
 //登录功能
public Employee Login(long empId, String password) {

    Employee e=this.findById(empId);
    if(e!=null&& Objects.equals(password, e.getEmpPassword())) {
        return e;
    }
    return null;


}
    public boolean changePassword(Long empId, String oldPassword, String newPassword) {
        Employee e=this.findById(empId);
        if(e!=null&& Objects.equals(oldPassword, e.getEmpPassword())) {
            e.setEmpPassword(newPassword);
            employeeDao.update(e);
            return true;
        }
       else return false ;
    }
    @Override
    public void create(Employee employee) {
        employeeDao.create(employee);
    }

    @Override
    public List<Employee> findAll() {
        return employeeDao.findAll();
    }

    @Override
    public Employee findById(Long id) {
        return  employeeDao.findById(id);
    }

    @Override
    public void update(Employee employee) {
         employeeDao.update(employee);
    }

    @Override
    public void deleteById(Long id) {
        employeeDao.deleteById(id);
    }


}
